﻿namespace NHibernateCodeGenerator
{
    using System;
    using System.IO;
    using System.Text;

    public class NhbFileGenerator
    {
        public static void CreateNhbClassFile(string savePath, string classCode, string className)
        {
            string path = savePath + @"\Entities";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            using (StreamWriter writer = new StreamWriter(path + @"\" + Common.StringFirstCharToUpper(className) + ".cs", false, Encoding.UTF8))
            {
                writer.Write(classCode);
            }
        }

        public static void CreateNhbXmlFile(string savePath, string xmlCode, string className)
        {
            string path = savePath + @"\Mappings";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            using (StreamWriter writer = new StreamWriter(path + @"\" + Common.StringFirstCharToUpper(className) + ".hbm.xml", false, Encoding.UTF8))
            {
                writer.Write(xmlCode);
            }
        }
    }
}

